package com.xs.demo.service;

import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.xs.demo.entity.Userinfo;

public class ImporService {
	
	public static List<Userinfo> getAllByExcel(InputStream fis) {
		List<Userinfo> list = new ArrayList<Userinfo>();
		Userinfo userinfo = null;
		try {
			HSSFWorkbook hwb = new HSSFWorkbook(fis);
			HSSFSheet sheet = hwb.getSheetAt(0);
			HSSFRow row = null;
			DateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			
			for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
				sheet = hwb.getSheetAt(i);
				for (int j = 1; j < sheet.getPhysicalNumberOfRows(); j++) {
					row = sheet.getRow(j);
					userinfo = new Userinfo();
					userinfo.setId(0);
					userinfo.setName(row.getCell(1).toString());
					userinfo.setAddress(row.getCell(2).toString());
					
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return list;
		
	}
}
